
filename = dir('c:\manoj\projects\plasma\at_150km\all_w\w*');


for i = 1:length(filename),
    fid = fopen(['c:\manoj\projects\plasma\at_150km\all_w\' filename(i).name],'rt');

S = fgetl(fid);
Header = fgetl(fid);
datef = datevec(Header(1:11));
S = fgetl(fid);
S = fgetl(fid);
S = fgetl(fid);
S = fgetl(fid);

for j = 1:132,
   S = fgetl(fid);
  [Data] = sscanf(S,'%f');
  fday(i,j) = datenum(datef(1),datef(2),datef(3),Data(1)+5,Data(2),Data(3))-datenum(2000,1,1);
  t(i,j) =    datenum(datef(1),datef(2),datef(3),Data(1),Data(2),Data(3));
  w(i,j) = Data(4);
  sigma(i,j) = Data(5);
end;

fclose(fid);
end;

for i = 1:132,
numdata(i) = sum(~isnan(w(:,i)));
end;

for i = 1:132,
L = isnan(w(:,i));
dd(i) =std(w(~L,i));
end;

subplot(311)
plot(t(1,:),nanmean(w))
ylabel('w m/s');
datetick;

subplot(312)
plot(t(1,:),numdata)
ylabel('Number of data');
datetick;

subplot(313);
plot(t(1,:),nanmean(sigma));
datetick;
ylabel('STD');
fclose all;
%save e:\manoj\projects\plasma\julia_data fday w sigma t;


%12-march-2008 fill in missing data Julia

 % this file (Julia_W_new.mat-generated from the following scripts) contains corrected Julia W. The correction
 % was interploation of data for 1-2 missiing point.
 % In addition, the Julia data is now up to 2008 Feb 11. However, this
 % database doesnot have the polinomial fit as in Julia_PLP.mat 
 % The new processing scripts can be found in julia.m. date 11mar08
% the max number of missiing points allowed is 3 (test with 2 results
% almost same)
load c:\manoj\projects\plasma\Julia_PLP.mat w_new Julia_W_new fday_new;


gh = [1:132];

for i = 1:1002,
    L = isnan(w_new(i,:));
    Julia_W_new(i).k = gh(~L);
end;

w = w_new;
Julia_W = Julia_W_new;
fday = fday_new;


ncount=0;
for i = 1: 1002,
Julia_W(i).fday = floor(fday(i,100));
if sum(diff(Julia_W(i).k))+1 ~= length(Julia_W(i).k) & length(Julia_W(i).k) > 5,
if sum(isnan(w(i,Julia_W(i).k(1):Julia_W(i).k(end)))) <= 3 & max(diff(Julia_W(i).k)) <=3,
    fprintf('Number of missing data = %d, maximum gap length = %d\n',sum(isnan(w(i,Julia_W(i).k(1):Julia_W(i).k(end)))),max(diff(Julia_W(i).k)));
    %plot(interp1(Julia_W(i).k,w(i,Julia_W(i).k),Julia_W(i).k(1):Julia_W(i).k(end)));
    w(i,Julia_W(i).k(1):Julia_W(i).k(end))=interp1(Julia_W(i).k,w(i,Julia_W(i).k),Julia_W(i).k(1):Julia_W(i).k(end));
%     hold on;
%     plot(w(i,Julia_W(i).k(1):Julia_W(i).k(end)),'r');
%     pause;
%     hold off;
ncount=ncount+1;
Julia_W(i).k = Julia_W(i).k(1):Julia_W(i).k(end);
end;
end;
end;

save c:\manoj\projects\ace\Julia_W_new w Julia_W fday;